package com.igorkundovic.guitarstab.pages;

import java.util.LinkedList;
import java.util.List;

import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.BeginRender;
import org.apache.tapestry5.annotations.CleanupRender;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;


import com.igorkundovic.guitarstab.User;
import com.igorkundovic.guitarstab.service.TabService;
import com.igorkundovic.guitarstab.Tab;
import com.igorkundovic.guitarstab.beans.*;


public class AllTabs {

	
	@ApplicationState
	@Property
	private User user;
	private boolean userExists;
	@Inject
	private TabService tabservice;	
	@Property
	private List<Tab> tabs=new LinkedList<Tab>();
	@Property 
	private TabBean tabbean;
	@Property
	@Persist
	private String message2;
	
	
	public Object onActivate(){
		
		if(userExists){
			return null;
		}
		return Welcome.class;
	}
	
	
	@SetupRender
	void setUp(Long id){
		
		tabs=tabservice.retrieve();
		
		String messsage3=null;
		
		if(tabs.isEmpty())
			messsage3="No one posted a tab! Be the first one by clicking on link Upload tabs...";
		
		message2=messsage3;
		
	}
	
	
	public boolean isUserExists() {
		return userExists;
	}
	
	@CleanupRender
	public void cleanUp(){
		message2=null;
		}
	
     
	

	
}
